﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using Wuqi.Webdiyer;

namespace Heyu.Utility
{
    /// <summary>
    /// 分页
    /// </summary>
    public class Pager
    {
        public Pager()
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="dt">数据源</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="pageIndex">页面</param>
        /// <param name="recordCount">总记录数</param>
        /// <returns></returns>
        public static PagedDataSource pager(DataTable dt, int pageSize, int pageIndex, out int recordCount)
        {
            PagedDataSource pds = new PagedDataSource();

            pds.DataSource = dt.DefaultView;
            pds.AllowPaging = true;
            pds.PageSize = pageSize;
            pds.CurrentPageIndex = pageIndex - 1;

            recordCount = pds.DataSourceCount;
            return pds;
        }
        public static PagedDataSource pager(DataTable dt, AspNetPager AspNetPager1)
        {
            int recordCount = 0;
            PagedDataSource pds = pager(dt, AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, out recordCount);
            AspNetPager1.RecordCount = recordCount;

            return pds;
        }
        public static PagedDataSource pager(DataTable dt, int pageSize, int pageIndex)
        {
            int recordCount = 0;
            return pager(dt, pageSize, pageIndex, out recordCount);
        }

    }
}
